//
//  Radio_Hot_TableViewCell.m
//  Time
//
//  Created by dllo on 16/7/23.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Radio_Hot_TableViewCell.h"
#import "Radio_Hot_CollectionViewCell.h"

@interface Radio_Hot_TableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,retain) UICollectionView *hotCollectionView;

@end

@implementation Radio_Hot_TableViewCell

-(void)dealloc{
    [_hotArray release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake((SWIDTH - 10) / 2.0, (SWIDTH - 10) / 2.0 + 50);
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0;
        
        self.hotCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SWIDTH, (SWIDTH - 10) + 100) collectionViewLayout:flowLayout];
        [self.contentView addSubview:self.hotCollectionView];
        self.hotCollectionView.delegate = self;
        self.hotCollectionView.dataSource = self;
        self.hotCollectionView.backgroundColor = [UIColor whiteColor];
        [self.hotCollectionView registerClass:[Radio_Hot_CollectionViewCell class] forCellWithReuseIdentifier:@"Radio_Hot_CollectionView_Cell"];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
}

-(void)setHotArray:(NSMutableArray *)hotArray{
    if (_hotArray != hotArray) {
        [_hotArray release];
        _hotArray = [hotArray retain];
    }
    [self.hotCollectionView reloadData];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.hotArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    Radio_Hot_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Radio_Hot_CollectionView_Cell" forIndexPath:indexPath];
    cell.model = [self.hotArray objectAtIndex:indexPath.item];
    
    return cell;
}

@end
